{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy  as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib as mpl\n",
    "from sklearn import datasets\n",
    "iris=datasets.load_iris()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X=iris.data\n",
    "y=iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "X=X[y<2,:2]#选用y=0,y=1两种类型。选前两列（前两个特征）\n",
    "y=y[y<2]#y对应两种类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x1caffb19640>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGgCAYAAAB45mdaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtsUlEQVR4nO3df3DU9Z3H8de6kETaJIeeCZHdkjaloAIHaE+Ch8QT5UY6A5PReoqid3BXNdwl5cqPdJizWq/xgm31RtNSO5KbQY4pEKWnnIqoyCDtIZS7gB5FRIwxwf6hCT+c4CWf+2MvWTbJJvvju/v9fL95PmZ2MN/97Ob9fX+/+e7b/X6+33fAGGMEAADgkovcDgAAAIxsFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVFCMAAMBVaRUjjz76qAKBgGpqauKOaWxsVCAQiHnk5eWl82sBAICPjEr1hfv379f69es1bdq0YccWFBTo6NGjfT8HAoGkfldPT48+/vhj5efnJ/1aAADgDmOMTp8+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GxUwqimf06NGaMWOG3nvvvSxE7C1/9Ed/pG984xtxczNu3DidOnUqZtmpU6c0bty4bITnOcPlsz/2zaiSkhJdeeWVMcuuuOKKIU97xds/CwoKdPHFF2ckTq9IJZ+D+dM//VP2z/938uRJvfrqq1q2bNmQ49w6blKMZNCNN96o5uZmHTp0qO9xzTXXaPHixTp06JCCweCw79Hd3a3m5maVlJRkIWJvOXPmjI4fPx43N+Xl5dq1a1fMsp07d6q8vDwb4XnOcPnsj30z6rrrrou5ykiSfv/732vChAlxX8P+GV8q+RzMoUOH2D//34YNG1RUVKQFCxYMOc61/TKj37tggP6nae6++26zZs2avp8feugh8/LLL5vjx4+bAwcOmL/8y780eXl55siRIy5Ea5d/+Id/MG+88YY5ceKE2bt3r5k3b5754z/+Y/PJJ58YYwbmcu/evWbUqFHmscceM++++6558MEHzejRo01zc7Nbq2CVZPPJvhnff/7nf5pRo0aZf/qnfzLHjh0zzz77rBkzZozZuHFj35g1a9aYu+++u+/n999/34wZM8asXLnSvPvuu+app54ywWDQvPTSS26sglVSyedPf/pT8/zzz5tjx46Z5uZmU11dbS666CLz6quvurEKVunu7jZf+cpXzOrVqwc8Z8txk2Iky/oXI3PnzjX33HNP3881NTXmK1/5isnJyTHFxcXmlltuMQcPHsx+oBa6/fbbTUlJicnJyTHjx483t99+u3nvvff6nu+fS2OM+dWvfmW+8Y1vmJycHHPVVVeZF198MctR2yvZfLJvDu3f//3fzZQpU0xubq6ZPHmy+cUvfhHz/D333GPmzp0bs+z1118306dPNzk5OeZrX/ua2bBhQ/YCtlyy+fznf/5nU1ZWZvLy8swll1xiKioqzGuvvZblqO308ssvG0nm6NGjA56z5bgZMMaYzH73AgAAEB9zRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKsoRgAAgKv+D25CKuM3ZArrAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[y==0,0],X[y==0,1],color=\"r\")#y=0类型，前两个特征的分布\n",
    "plt.scatter(X[y==1,0],X[y==1,1],color=\"blue\")#y=1类型，前两个特征的分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "调用逻辑回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<LogicRegression.LogisticRegression at 0x1caffcd1b50>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from LogicRegression import LogisticRegression\n",
    "log_reg=LogisticRegression()\n",
    "log_reg.fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.score(x_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.03371646, 0.01150563, 0.95952428, 0.87664158, 0.01150563,\n",
       "       0.17620804, 0.94063207, 0.9862351 , 0.11508681, 0.0500032 ,\n",
       "       0.20738117, 0.74278923, 0.74278923, 0.10464386, 0.03737668,\n",
       "       0.97257982, 0.1367659 , 0.32290382, 0.87752154, 0.97247077])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.predict_proba(x_test)#每个元素都是0-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test#与概率矩阵的对应<=0.5为0，>=0.5为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
